/**
 *  Copyright (c)  2011-2020 Panguso, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Panguso, 
 *  Inc. ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into with Panguso.
 */


/*

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.thu.log.tree;

/**
 * 多叉树
 * 
 * @author wan
 */
public class ManyTree {

	private ManyTreeNode root = null;
/**
 * 
 * @param root parameter
 */
	public ManyTree(ManyTreeNode root) {
		this.root = root;
	}

	// 中序遍历多叉树
	/**
	 * 
	 * @param treeNode parameter
	 * @return
	 */
	public String iteratorTree(ManyTreeNode treeNode) {

		StringBuilder sb = new StringBuilder();
		if (treeNode != null) {
			if ("1".equals(treeNode.getData().getKey())) {
				sb.append(treeNode.getData().getKey() + ",");
			}

			for (ManyTreeNode index : treeNode.getChildList()) {
				sb.append(index.getData().getKey() + ",");
				if (index.getChildList() != null
						&& index.getChildList().size() > 0) {
					sb.append(iteratorTree(index));
				}
			}
		}
		return sb.toString();
	}

	/**
	 * @return the root
	 */
	public ManyTreeNode getRoot() {
		return root;
	}

	/**
	 * @param root
	 *            the root to set
	 */
	public void setRoot(ManyTreeNode root) {
		this.root = root;
	}

}
